﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;

namespace FileLog
{
    public class FileLogOptins
    {
        public string LogsDirectory { get; set; } = "logs";
        public string FileName { get; set; } = "app.log";
        /// <summary>
        /// 设置logs目录，如果为空则为程序当前目录
        /// </summary>
        public string? LogsDir { get; set; }
        public RollingInterval RollingInterval { get; set; } = RollingInterval.Day;
        public LogLevel MinimumLevel { get; set; } = LogLevel.Information;
        /// <summary>
        /// 将日志转换为什么样的格式
        /// string:categoryName,LogLevel,Exception,string:description 
        /// return string
        /// </summary>
        public Func<string, LogLevel, Exception?, string, DateTimeOffset, string?>? LogFormatter { get; set; }
       = (c, l, e, m, t) =>
       {
           var err = e == null ? null : e.ToString() + "\n";
           return $"{t},{c},{l},{m}{Environment.NewLine}{err}";
       };
        //可以使用Logging
        public virtual void Configure(IConfiguration configuration) => configuration.Bind(this);
    }
}
